package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.api.RecommendUserApi;
import com.tanhua.dubbo.pojo.RecommendUser;
import com.tanhua.dubbo.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    /**
     * 根据用户id查询今日佳人
     *
     * @param id
     * @return
     */
    public TodayBest queryTodayBest(Long id){
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if (recommendUser != null) {
            TodayBest todayBest = new TodayBest();
            todayBest.setId(recommendUser.getUserId()); //推荐结果的用户id
            double score = Math.floor(recommendUser.getScore()); //取整,98.2 -> 98
            todayBest.setFateValue(Double.valueOf(score).longValue());
            return todayBest;
        }

        return null;
    }

    /**
     * 查取得分靠前
     * /的用户
     *
     * @param id
     * @param page
     * @param pagesize
     * @return
     */
    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(id, page, pagesize);
    }
}
